home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mdishe / error.bas < prev    next >
BASIC Source File  |  1994-12-28  |  6KB  |  187 lines

  1. ' ********************************************************
  2. '        MDI Standard Application Shell
  3. ' ********************************************************
  4. '
  5. ' SUMMARY
  6. ' -------
  7. ' This file is part of an MDI application "skeleton"
  8. ' created by John Blessing of Leigh Business Enterprises Ltd.
  9. '
  10. ' FEATURES
  11. ' --------
  12. ' Selection of application database.
  13. ' Compact/Repair of database.
  14. ' 'Helptips' on toolbar items.
  15. ' Support for Help files.
  16. ' MDI child forms tiling etc.
  17. ' Error trapping.
  18. ' 'Nag' screen support for shareware authors.
  19. ' Support for 3D dialogs (switched off in design mode
  20. '   to prevent GPFs)
  21. '
  22. ' USE
  23. ' ---
  24. ' You need VB Pro to use this shell, although it could be
  25. ' modified to run under the standard edition.
  26. '
  27. ' You will need to set up some information in APP.BAS,
  28. ' particularly in SetAppInfo().  You will also need to add
  29. ' your own application specific code to this module.
  30. '
  31. ' DISTRIBUTION
  32. ' ------------
  33. ' This program is "FreeWare" and may be used and distributed
  34. ' as you wish.
  35. '
  36. ' It incorporates some ideas/code from other authors and these
  37. ' are acknowledged in the appropriate module.
  38. '
  39. ' We hope that you will find it useful.  If you wish to discuss it
  40. ' then please e-mail us on Compuserve 100444,623.
  41. '
  42. ' ADVERTISEMENT!
  43. ' --------------
  44. ' Are you looking for a helpdesk system? Or does your company
  45. ' want to track and monitor the progress of any work activity?
  46. ' We market a system which could be of interest to you.
  47. '
  48. ' PROGRESS is available for download from the Business section
  49. ' of the Windows Shareware forum on Compuserve
  50. ' (filename PRGRSS10.ZIP).  It's a large program, so in the
  51. ' same section you will also find the help files and
  52. ' documentation as  PRGSSDOC.ZIP which is quicker to download
  53. ' and will give you a good idea of the functionality of PROGRESS.
  54. '
  55. ' Dec 1994
  56. '
  57. '
  58. 'The routines in this module were adapted from those
  59. 'from an article in the July/August 1994 edition of
  60. 'VB User
  61. Option Explicit
  62.  
  63.  
  64. '======================================================================
  65. 'Form/Module:
  66. '   Error.bas
  67. '
  68. 'Procedure:
  69. '   bDesignMode
  70. '
  71. 'Modifications:
  72. '   23/12/94   JBL     Build
  73. '
  74. 'Description:
  75. '   Detects if the program is running in the design environment
  76. '======================================================================
  77. Function bDesignMode () As Integer
  78.     Static bCalled      As Integer  'holds whether or not been called before
  79.     Static bMode        As Integer  'holds VB mode
  80.     Dim hInstanceForm   As Integer
  81.     Dim hInstanceVB     As Integer
  82.     Dim nVBMainWIndow   As Integer
  83.  
  84.  
  85.     
  86.     'errorhandler
  87.     On Error GoTo Error_bDesignMode
  88.  
  89.     If Not bCalled Then
  90.         'not been called before so calc if in design mode
  91.         
  92.         'check to see if any forms loaded
  93.         If Forms.Count > 0 Then
  94.             'there are some forms
  95.  
  96.             'signal that been called
  97.             bCalled = True
  98.  
  99.             'try and find VB's hidden design window
  100.             nVBMainWIndow = FindWindow("ThunderMain", 0&)
  101.             If nVBMainWIndow = 0 Then
  102.                 'not in design mode
  103.                 bMode = False
  104.             Else
  105.                 'in design mode
  106.                 'now check our form's hinstance against VB's
  107.                 'run-time window's to make sure that it's US
  108.                 'that is being worked on
  109.  
  110.                 'get the hinstance of our first form
  111.                 hInstanceForm = GetWindowWord(Forms(0).hWnd, GWW_HINSTANCE)
  112.  
  113.                 'get hinstance of VB's hidden window
  114.                 hInstanceVB = GetWindowWord(nVBMainWIndow, GWW_HINSTANCE)
  115.  
  116.                 'check if they match
  117.                 If hInstanceForm = hInstanceVB Then
  118.                     'in design mode
  119.                     bMode = True
  120.                 Else
  121.                     bMode = False
  122.                 End If
  123.             End If  'end of having found ThunderMain
  124.  
  125.         Else
  126.             'no forms loaded
  127.             MsgBox "bDesignMode () cannot be called if there are no forms currently loaded.", MB_OK Or MB_ICONSTOP, "Error"
  128.         
  129.         End If  'end of check for any forms
  130.  
  131.     End If  'end of check if been called before
  132.  
  133.     'set return value
  134.     bDesignMode = bMode
  135.  
  136.     Exit Function
  137.  
  138.  
  139. Error_bDesignMode:
  140.  
  141.     MsgBox "Error " & CStr(Err) & ". " & Error$ & ".  At line " & CStr(Erl) & "."
  142.     Resume Exit_bDesignMode
  143.  
  144. Exit_bDesignMode:
  145. End Function
  146.  
  147. '======================================================================
  148. 'Form/Module:
  149. '   Error.Bas
  150. '
  151. 'Procedure:
  152. '   GenErrorHandler
  153. '
  154. 'Modifications:
  155. '   23/12/94   JBL     Build
  156. '
  157. 'Description:
  158. '   Displays a standard message box and logs error to error file
  159. '   if required
  160. '   Author: Peter J Morris TMS (International) ltd.
  161. '======================================================================
  162. '
  163. Sub GenErrorHandler (Location As String, ErrNum As Integer, ErrorText As String)
  164.     
  165.     Dim Message As String
  166.     Dim FileNum As Integer
  167.  
  168.     Message = "Error no. " & CStr(ErrNum) & " in " & Location & "."
  169.     Message = Message & sGNl & ErrorText
  170.  
  171.     MsgBox Message, MB_OK Or MB_ICONEXCLAMATION
  172.  
  173.     'write to error file if specified
  174.     If tGApp.sErrorFile <> "" Then
  175.         'add in the date and time
  176.         Message = Message & sGNl & "Date and time: " & Now
  177.  
  178.         FileNum = FreeFile
  179.         Open tGApp.sErrorFile For Append Access Write As FileNum
  180.         Print #FileNum, Message
  181.         Close #FileNum
  182.     End If
  183.  
  184.     
  185. End Sub
  186.  
  187.